<template>
  <div>
    <van-nav-bar title="设置密码" left-arrow @click-left="onClickLeft" />

    <van-form @submit="onSubmit" class="form">
      <van-field
        v-model="userInfo.mobile"
        name="用户名"
        placeholder="请输入手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      >
        <template #button>
          <span
            v-show="sendAuthCode"
            class="auth_text auth_text_blue"
            @click="getAuthCode"
            >获取验证码</span
          >
          <span v-show="!sendAuthCode" class="auth_text">
            <span class="auth_text_blue">{{ auth_time }} </span>
            秒之后重新发送验证码</span
          >
        </template>
      </van-field>
      <van-field
        center
        clearable
        placeholder="请输入验证码"
        v-model="userInfo.sms_code"
      >
      </van-field>
      <van-field
      v-model='userInfo.password'
        type="password"
        name="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="warning" native-type="submit">
          登录
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { lzGetSMS, lzpassword } from "../../utils/http";
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      sendAuthCode: true,
      auth_time: 0,
        userInfo: {
        mobile: "19801237380",
        password: "",
        sms_code: "",
        sms_type: "getPassword",
        type: 1,
        client: 1,
      },
    };
  },
  mounted() {},
  methods: {
    onClickLeft() {
      this.$router.push("/shezhi");
    },
   async onSubmit(values) {
     const res = await lzpassword(this.userInfo);
      console.log(res);
      this.$router.push('/mine')
    },
   async getAuthCode() {
      //发送验证码
      const res = await lzGetSMS(this.userInfo)
      console.log(res)

      //验证码倒计时
      this.sendAuthCode = false;
      this.auth_time = 30;
      var auth_timetimer = setInterval(() => {
        this.auth_time--;
        if (this.auth_time <= 0) {
          this.sendAuthCode = true;
          clearInterval(auth_timetimer);
        }
      }, 1000);
    },
  },
  computed: {},
  watch: {},
  created() {},
};
</script>

<style scoped>
</style>
